#!/bin/bash

echo "expr 计算"
num1=111
num2=12

num3=$(expr $num1 + $num2)
echo ${num3}

num3=$(expr $num1 \/ $num2)
echo ${num3}

num3=$(expr $num1 \* $num2)
echo ${num3}


num3=$[ $num1 + $num2 ]
echo ${num3}

num3=$[ $num1 / $num2 ]
echo ${num3}

num3=$[ $num1 * $num2 ]
echo ${num3}


# 使用bc进行数学运算
var1=1234
var2=44
result=$(echo "scale=4; $var1 / $var2" | bc)
echo "\$(echo \"scale=4; \$var1 / \$var2\" | bc) = $result"

result=$(echo "scale=4; 3.55 / 1.33" | bc)
echo "\$(echo \"scale=4; 3.55 / 1.33\" | bc) = ${result}"

var3=234
var4=532

echo "======="
echo "使用bc结合EOF进行数学运算"
# 使用bc结合EOF进行数学运算
var5=$(bc<<EOF
scale = 4
num1 = ($var1/$var2)
num2 = ($var3/$var4)
num1 + num2
EOF
)
echo "var5=${var5}"

